package cn.cmdr.controller;

import cn.cmdr.pojo.Permission;
import cn.cmdr.pojo.Staff;
import cn.cmdr.service.*;
import cn.cmdr.vo.ResultVo;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class indexcontroller {
    @Resource
    private PermissionService permissionService;
    @Resource
    private OrderService orderService;
    @Resource
    private ComService comService;
    @Resource
    private ReturnsService returnsService;

    @RequestMapping("index")
    public String index2(Model model) {
//        List<Permission> list = permissionService.getPerMenus();
//        model.addAttribute("list",list);
//        Staff staff = (Staff) SecurityUtils.getSubject().getPrincipal();
//        model.addAttribute("staff", staff);
        return "index";
    }

    @RequestMapping("ii")
    @ResponseBody
    public ResultVo ii() {
        List<Permission> list = permissionService.getPerMenus();
        return ResultVo.sucess(list);
    }

    @RequestMapping("/{f}/{p}/index")
    public String index(@PathVariable("f") String f, @PathVariable("p") String p) {
        return f + "/" + p;
    }

    @RequestMapping("/home")
    public String home(Model model) {
        model.addAttribute("z", orderService.getCount(null));
        model.addAttribute("dfk", orderService.getCount(0));
        model.addAttribute("dfh", orderService.getCount(1));
        model.addAttribute("yfh", orderService.getCount(2));
        model.addAttribute("ygb", orderService.getCount(3));
        model.addAttribute("ywc", orderService.getCount(4));
        model.addAttribute("sz", comService.getCount(null));
        model.addAttribute("sxj", comService.getCount(0));
        model.addAttribute("ssj", comService.getCount(1));
        model.addAttribute("kcjz", comService.getKCount());
        model.addAttribute("qrsh", returnsService.getCount(2));
        model.addAttribute("thdd", returnsService.getCount(1));
        model.addAttribute("dsh", comService.getVCount(0));
        model.addAttribute("ytg", comService.getVCount(1));
        model.addAttribute("jj", comService.getVCount(2));
        return "home";
    }

    @GetMapping("/login")
    public String login() {
        return "login";
    }

}